package com.biancheng.biancheng.biancheng6;

public class 赎金信 {
    /**
     * 输入：ransomNote = "aa", magazine = "ab"
     * 输出：false
     * @param args
     */
    public static void main(String[] args) {
        赎金信 ff = new 赎金信();
        boolean flag = ff.canConstruct("aa","ab");
        System.out.println(flag);
    }

    public boolean canConstruct(String ransomNote, String magazine) {
        // 统计ransomNote和magazine出现的字符次数
        if (ransomNote.length() > magazine.length()) {
            return false;
        }
        int[] cnt = new int[26];
        for (char c : magazine.toCharArray()) {
            cnt[c - 'a']++;
        }
        for (char c : ransomNote.toCharArray()) {
            cnt[c - 'a']--;
            if(cnt[c - 'a'] < 0) {
                return false;
            }
        }
        return true;
    }

}
